package com.changpay.zywy.ui.activity.mine
import android.text.TextUtils
import com.changpay.zywy.R
import com.changpay.zywy.base.BaseActivity
import com.changpay.zywy.base.IView
import com.changpay.zywy.constant.Constant
import com.changpay.zywy.ext.showToast
import com.changpay.zywy.utils.ImageLoader
import com.changpay.zywy.utils.Preference
import kotlinx.android.synthetic.main.activity_already.*
import kotlinx.android.synthetic.main.title_layout.*
import org.jetbrains.anko.sdk27.coroutines.onClick


class AlreadyActivity : BaseActivity(), IView {



    private var head_image: String by Preference(Constant.HEAD_IMAGE, "")
    private var true_name: String by Preference(Constant.TRUE_NAME, "")
    private var card_number: String by Preference(Constant.CARD_NUMBER, "")


    override fun attachLayoutRes(): Int {
        return R.layout.activity_already
    }

    override fun showLoading() {

    }

    override fun hideLoading() {

    }

    override fun showDefaultMsg(msg: String) {
        showToast(msg)
    }

    override fun showMsg(msg: String) {
        showToast(msg)
    }

    override fun showError(errorMsg: String) {
        showToast(errorMsg)
    }




    override fun initData() {
    }

    override fun initView() {
        tv_title.text = "实名认证"
        iv_back.onClick { finish() }
       ImageLoader.loadAvatar(head_image,iv_head)
        tv_name.text = true_name
        val string = bianString(card_number)
        tv_idcard.text = string
    }

    override fun start() {

    }


    private fun bianString(pNumber: String): String {
        if (!TextUtils.isEmpty(pNumber) && pNumber.length > 12) {
            val sb = StringBuilder()
            for (i in 0 until pNumber.length) {
                val c = pNumber[i]
                if (i >= 1 && i <= 11) {
                    sb.append('*')
                } else {
                    sb.append(c)
                }
            }
            return sb.toString()
        }
        return pNumber
    }

}
